<?php
    $this->layout('base.phtml', [
        'title' => _('New link'),
        'canonical' => url_full('new collection link', ['id' => $collection->id]),
        'has_errors' => $error || $errors,
        'modal_enabled' => true,
    ]);
?>

<div class="section">
    <div class="section__title">
        <h1 id="modal-title"><?= _('New link') ?></h1>
    </div>

    <form method="post" action="<?= url('create collection link', ['id' => $collection->id]) ?>">
        <?= $this->include('alerts/_error.phtml', ['message' => $error]) ?>

        <input type="hidden" name="csrf" value="<?= csrf_token() ?>" />
        <input type="hidden" name="from" value="<?= $from ?>" />

        <div class="form-group <?= isset($errors['url']) ? 'form-group--invalid' : '' ?>">
            <label for="url">
                <?= _('What’s the address of the link?') ?>
            </label>

            <input
                id="url"
                name="url"
                type="url"
                placeholder="https://…"
                required
                value="<?= $url ?>"
                autocomplete="off"
                autofocus
                aria-describedby="url-desc"
            />

            <div id="url-desc">
                <?php if (isset($errors['url'])): ?>
                    <p class="form-group__error">
                        <span class="sr-only"><?= _('Error') ?></span>
                        <?= $errors['url'] ?>
                    </p>
                <?php endif; ?>

                <p class="form-group__caption">
                    <?= _('It can be copy-paste from the <abbr>URL</abbr> bar, at the top of your browser.') ?>
                </p>
            </div>
        </div>

        <div class="form-group">
            <input
                type="checkbox"
                id="is-hidden"
                name="is_hidden"
                <?= $is_hidden ? 'checked' : '' ?>
            />

            <label class="label--checkbox" for="is-hidden">
                <?= _('Hide this link in public collections') ?>
            </label>
        </div>

        <div class="form__actions">
            <button type="submit" class="button--primary">
                <?= _('Add the link') ?>
            </button>
        </div>
    </form>
</div>
